<template>
  <el-container>
    <!-- ASIDE -->
    <el-aside width="200">
      <h1 class="logo"></h1>

      <el-menu
        :default-active="$route.path"
        class="el-menu-vertical-demo"
        text-color="#4e5bf8"
        ref="sideMenu"
        active-text-color="#E47833"
        :collapse="isCollapse"
      >
        <qf-sub-menu :sideMenu="userMenu"></qf-sub-menu>
      </el-menu>

      <!-- <el-row class="tac">
        <el-col :span="12">
          <el-menu
            :collapse="isCollapse"
            default-active="2"
            class="el-menu-vertical-demo"
          >
            <el-menu-item index="1">
              <i class="iconfont icon-shouye1"></i>
              <span slot="title">管理首页</span>
            </el-menu-item>

            <el-submenu index="2">
              <template slot="title">
                <i class="iconfont icon-xueyuan1"></i>
                <span>学员管理</span>
              </template>
              <el-menu-item index="2-1">
                <i class="iconfont icon-shangpinguanli"></i>
                <span slot="title">学员项目管理</span>
              </el-menu-item>
              <el-menu-item index="2-2">
                <i class="iconfont icon-shuju1"></i>
                <span slot="title">学员资料</span>
              </el-menu-item>
              <el-menu-item index="2-3">
                <i class="iconfont icon-shouye"></i>
                <span slot="title">学员宿舍</span>
              </el-menu-item>
            </el-submenu>

            <el-menu-item index="3">
              <i class="iconfont icon-kaoqin3"></i>
              <span slot="title">考勤管理</span>
            </el-menu-item>

            <el-menu-item index="4">
              <i class="iconfont icon-yonghu"></i>
              <span slot="title">用户管理</span>
            </el-menu-item>

            <el-menu-item index="5">
              <i class="iconfont icon-shuju2"></i>
              <span slot="title">数据统计</span>
            </el-menu-item>

            <el-menu-item index="6">
              <i class="iconfont icon-wode"></i>
              <span slot="title">我的中心</span>
            </el-menu-item>

            <el-submenu index="7">
              <template slot="title">
                <i class="iconfont icon-VIP4"></i>
                <span>vip管理</span>
              </template>
              <el-menu-item index="7-1">
                <i class="iconfont icon-chongzhi"></i>
                <span>vip充值</span>
              </el-menu-item>
              <el-menu-item index="7-2">
                <i class="iconfont icon-dd"></i>
                <span>订单管理</span>
              </el-menu-item>
            </el-submenu>
          </el-menu>
        </el-col>
      </el-row> -->
    </el-aside>
    <el-container>
      <!-- HEADER -->
      <el-header>
        <el-row type="flex" justify="space-between">
          <!-- left -->
          <el-col :span="6">
            <div class="grid-content left">
              <i
                @click="isCollapse = !isCollapse"
                :class="[
                  'iconfont',
                  'changeMenu',
                  isCollapse ? 'icon-fold-right' : 'icon-shouqi1',
                ]"
              ></i>
            </div>
          </el-col>
          <!-- center -->
          <el-col :span="6">
            <div
              class="grid-content center"
              style="color: #fff; font-size: 2em"
            >
              crm系统
            </div>
          </el-col>
          <!-- right -->
          <el-col :span="6">
              <div class="grid-content right">
                <el-avatar shape="square" :size="40" :src="squareUrl"></el-avatar>
                <svg
                  class="icon vip_3"
                  aria-hidden="true"
                  v-if="userInfo.vipLevel"
                >
                  <use :xlink:href="'#' + vipIconName"></use>
                </svg>
                <el-dropdown :hide-on-click="false">
                  <span class="el-dropdown-link">
                    {{ userInfo.nickname }}
                    <i class="el-icon-caret-bottom" style="color: #fff"></i>
                  </span>
                  <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item
                      
                      icon="iconfont icon-VIP4"
                      v-if="userInfo.vipLevel"
                    >
                      vip到期时间:<br />{{ vipExpires }}
                    </el-dropdown-item>

                    <el-dropdown-item  icon="iconfont icon-VIP4">
                      vip充值
                    </el-dropdown-item>

                    <el-dropdown-item  icon="iconfont icon-icon-test" @click.native="toMine">
                      账号信息
                    </el-dropdown-item>

                    <el-dropdown-item
                      
                      icon="iconfont icon-shangpinguanli"
                    >
                      项目管理
                    </el-dropdown-item>

                    <el-dropdown-item
                      
                      icon="iconfont icon-chongzhi"
                      @click.native="quit"
                    >
                      退出
                    </el-dropdown-item>
                  </el-dropdown-menu>
                </el-dropdown>
              </div>
          </el-col>
        </el-row>
      </el-header>

      <!-- MAIN -->
      <el-main>
        <!-- 面包屑 -->
        <el-breadcrumb separator="/">
          <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
          <el-breadcrumb-item :to="{name: bread.name}" v-for="bread in breadCrumb" :key=bread.name>{{bread.meta.name}}</el-breadcrumb-item>
        </el-breadcrumb>
        <!-- 表格数据 -->
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>

</template>

<script>
import { mapState } from "vuex";
import moment from "moment";

export default {
  
  data() {
    return {
      isCollapse: false,
    };
  },
  computed: {
    ...mapState(["userInfo","userMenu","breadCrumb"]),
    squareUrl() {
      return this.userInfo?.headimgurl
        ? this.userInfo?.headimgurl
        : "https://cube.elemecdn.com/9/c2/f0ee8a3c7c9638a54940382568c9dpng.png";
    },
    vipIconName() {
      let { vipLevel } = this.userInfo;
      if (vipLevel === 1) {
        return "icon-vip";
      } else if (vipLevel === 2) {
        return "icon-vip2";
      } else if (vipLevel === 3) {
        return "icon-vip_3";
      } else {
        return "";
      }
    },
    vipExpires() {
      let { vipStamp } = this.userInfo;
      let date = moment(vipStamp).format("YYYY-MM-DD HH:mm:ss");
      return date;
    },
  },
  methods: {
    quit() {
      //移除过期token
      localStorage.removeItem("yz-token");
      //跳转到登录页
      this.$router.push("/login");
      //刷新页面
      location.reload();
    },
    toMine(){
      console.log("1");
      this.$router.push({name: "mine"})
    }
  },
};
</script>

<style lang="less" scoped>
.el-header,
.el-footer {
  background-color: #b3c0d1;
  color: #333;
  text-align: center;
  line-height: 60px;
}
.el-header {
  background: linear-gradient(135deg, #4c67ff, #5635df);
}

.el-aside {
  background-color: #d3dce6;
  color: #333;
  text-align: center;
  line-height: 200px;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  text-align: center;
  line-height: 160px;
}

body > .el-container {
  margin-bottom: 40px;
}
.el-container {
  height: 100%;
}
.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}

// aside
.el-aside {
  background: linear-gradient(135deg, #4c67ff, #5635df);
  .logo {
    background-image: url(http://chst.vip:8081/stu2/img/logo.be8bbddf.png);
    min-height: 60px;
    background-size: 80%;
    background-repeat: no-repeat;
    background-position: center;
  }
  /deep/ .el-menu-vertical-demo:not(.el-menu--collapse) {
    width: 200px;
    min-height: 400px;
  }
  // /deep/ .el-menu-item {
  //   text-align: left;
  // }
  // /deep/ .el-submenu__title {
  //   text-align: left;
  // }
  span {
    margin-left: 8px;
    color: #4c67ff;
  }
  /deep/ .iconfont {
    color: #4c67ff;
  }
}

// header
.el-row {
}
.icon {
  margin: 0 8px;
  width: 4em;
  height: 4em;
}
.el-col {
  border-radius: 4px;
}

.grid-content {
  border-radius: 4px;
  min-height: 36px;
  height: 60px;
}
.left {
  text-align: left;
  .changeMenu {
    color: #fff;
    font-size: 30px;
  }
}
.center {
}
.right {
  display: flex;
  justify-content: center;
  .headPic {
    vertical-align: middle;
  }
  b {
    .vip_3 {
      width: 75px;
      height: 24px;
    }
    .dropdown {
      display: inline-block;
      span {
        color: #f4c14f;
        margin-left: 8px;
      }
      .down {
        color: #fff;
        width: 23px;
      }
    }
  }
}
.row-bg {
  padding: 0;
  background-color: #f40;
}
.el-avatar {
  margin-top: 12px;
}
//dropdown
.el-dropdown-link {
  cursor: pointer;
  color: #409eff;
}
.el-icon-arrow-down {
  font-size: 12px;
}
.el-dropdown-menu {
  width: 200px;
  text-align: center;
  background: linear-gradient(135deg, #4c67ff, #5635df);
}
</style>